<template>
    <div class="page_content">
        <div class="data-content">
            <div style="display: flex;justify-content:center;align-items: center;height: 200rem;" v-show="isLoading">
                <a-spin size="large" :spinning="isLoading"></a-spin>
            </div>
            <div class="detail w-fixed-center" v-if="apiData.id">
                <!-- 基本信息 -->
                <img class="img" :src="imgDomainUrl + apiData.donation.img" alt="">
                <div class="title">{{ apiData.donation.title }}</div>
                <div class="tags">
                    <span>善款可追溯</span>
                    <span>每月有进展</span>
                </div>
                <div class="desc">{{ apiData.donation.desc }}</div>
                <div class="icon">
                    <span class="list">
                        <img src="@/assets/img/web/donation/list_icon1.png" alt="">
                        <div class="title ccyc1">上線籌款1年</div>
                        <div class="desc ccyc1">執行時間</div>
                    </span>
                    <span class="list">
                        <img src="@/assets/img/web/donation/list_icon2.png" alt="">
                        <div class="title ccyc1">已提交</div>
                        <div class="desc ccyc1">執行計劃&預算</div>
                    </span>
                    <span class="list">
                        <img src="@/assets/img/web/donation/list_icon3.png" alt="">
                        <div class="title ccyc1">累計反饋02次</div>
                        <div class="desc ccyc1">進展反饋</div>
                    </span>
                    <span class="list">
                        <img src="@/assets/img/web/donation/list_icon4.png" alt="">
                        <div class="title ccyc1">近1年披露1次</div>
                        <div class="desc ccyc1">財務披露</div>
                    </span>
                </div>
            </div>

            <!-- 最新进展 -->
            <div class="line w-fixed-center" v-if="progressTotal > 0"></div>
            <div class="progress w-fixed-center" v-if="progressTotal > 0">
                <div class="p_title_before">最新进展</div>
                <div class="list">
                    <a-timeline :pending="progressPending" color="red">
                        <a-timeline-item color="red" v-for="item_progress in progressList" :key="item_progress.id">
                            <div class="author">{{ item_progress.add_date }}&nbsp;&nbsp;{{
                                item_progress.author }}</div>
                            <div class="title">{{ item_progress.title }}</div>
                            <div class="content">
                                <textareaFormatShow :content="item_progress.content" :lineHeight="20">
                                </textareaFormatShow>
                            </div>
                        </a-timeline-item>
                        <a-timeline-item color="red"
                            v-if="progressCurrentPage < progressLastPage && progressPending === false"
                            @click="getProgressList">
                            <div class="more">
                                <span class="word">展开更多</span>
                                <img class="to_bottom_icon" src="@/assets/img/web/donation/to_bottom_icon.png" alt="">
                            </div>
                        </a-timeline-item>
                    </a-timeline>
                </div>
            </div>

            <!-- 筹款情况 -->
            <div class="line w-fixed-center" v-if="apiData.id"></div>
            <div class="situation w-fixed-center" v-if="apiData.id">
                <div class="p_title_before">项目筹款情况</div>
                <div class="more_desc">更多财务披露</div>
                <div class="title">截止一分钟前，已有</div>
                <div class="list">
                    <span class="box">
                        <div class="num">63,613,462</div>
                        <div class="text">次/爱心捐助</div>
                    </span>
                    <span class="box">
                        <div class="num">2,313,462</div>
                        <div class="text">元/总捐款金额</div>
                    </span>
                    <span class="box">
                        <div class="num">2,462</div>
                        <div class="text">个/人获得帮助</div>
                    </span>
                </div>
            </div>

            <!-- 项目介绍 -->
            <div class="line w-fixed-center" v-if="apiData.id"></div>
            <div class="introduce w-fixed-center" v-if="apiData.id">
                <div class="p_title_before">项目介绍</div>
                <div class="content" v-show="introduceIsShowMore">
                    <textareaFormatShow :content="apiData.donation.intro" :lineHeight="20">
                    </textareaFormatShow>
                </div>
                <div class="content ccyc3" v-show="!introduceIsShowMore">
                    {{ apiData.donation.intro }}
                </div>
                <div class="more_btn" @click="introduceShowMore()" v-show="!introduceIsShowMore">展开更多
                </div>
                <div class="more_btn" @click="introduceShowMore()" v-show="introduceIsShowMore">收起</div>
            </div>

            <!-- 项目预算及执行计划 -->
            <div class="line budget w-fixed-center" v-if="apiData.id"></div>
            <div class="introduce budget w-fixed-center" v-if="apiData.id">
                <div class="p_title_before">项目预算及执行计划</div>
                <div class="content" v-show="budgetIsShowMore">
                    <textareaFormatShow :content="apiData.donation.budget" :lineHeight="20">
                    </textareaFormatShow>
                </div>
                <div class="content ccyc3" v-show="!budgetIsShowMore">
                    {{ apiData.donation.budget }}
                </div>
                <div class="more_btn" @click="budgetShowMore()" v-show="!budgetIsShowMore">展开更多
                </div>
                <div class="more_btn" @click="budgetShowMore()" v-show="budgetIsShowMore">收起</div>
            </div>

            <!-- 机构信息 -->
            <div class="line w-fixed-center" v-if="apiData.id"></div>
            <div class="organization w-fixed-center" v-if="apiData.id">
                <div class="p_title_before">机构信息</div>
                <div class="title">
                    民政備案號:{{ apiData.donation.organization_num }}
                </div>
                <div class="agency">
                    执行与收款机构：{{ apiData.donation.organization_collection }}
                </div>
                <div class="person_list" v-if="apiData.donation.organization_author_arr.length > 0">
                    <div class="box" v-for="item_aa in apiData.donation.organization_author_arr">
                        <img class="head_img" :src="imgDomainUrl + item_aa.head_img" />
                        <div class="info">
                            <div class="name">
                                {{ item_aa.name }}&nbsp;&nbsp;{{ item_aa.position }}
                            </div>
                            <div class="desc">
                                {{ item_aa.desc }}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { message } from 'ant-design-vue';
import { ref, onMounted, inject } from 'vue';   //引入ref
import { getDonationDetail, getDonationProgressList } from "@/api/web";   //引入api
import { useRoute, useRouter } from 'vue-router';
import textareaFormatShow from '@/components/web/page/textarea_format_show.vue';   //引入textarea文本域格式化组件
//设置导航选中状态
import { webNavSelected } from '@/store/webNavSelected.js';
webNavSelected.set('donation');

const isLoading = ref(true);    // 控制loading

const { imgDomainUrl } = inject('imgDomainUrl');  // 依赖注入--文件、图片前的域名

const route = useRoute();
const router = useRouter();
// 获取 URL 中的查询参数（route.params获取restful参数、route.query获取?&a=b格式参数）
const id = route.params.id;
if (id == undefined || id == null || id == '') {
    router.go(-1);
}

// 接口获取到的数据
const apiData = ref({});

// 项目进展有关
const progressPending = ref(false);
const progressList = ref([]);
const progressCurrentPage = ref(1);
const progressLastPage = ref(1);
const progressTotal = ref(0);
const progressPageSize = ref(2);

// 获取数据
const getData = () => {
    //根据需求可以通过data传入参数
    const searchData = { id: id }
    getDonationDetail(searchData).then((res) => {
        isLoading.value = false;
        if (res === false) return;

        apiData.value = res.data;
        progressCurrentPage.value = apiData.value.progress.current_page;
        progressLastPage.value = apiData.value.progress.last_page;
        progressPageSize.value = apiData.value.progress.per_page;
        progressTotal.value = apiData.value.progress.total;
        progressList.value = apiData.value.progress.data;

    }).catch((rej) => {
        isLoading.value = false;
        message.error('错误：' + rej);
    });
}

//项目进展，获取更多列表
const getProgressList = () => {
    if (progressCurrentPage.value < progressLastPage.value) {
        progressPending.value = '加载中……';

        progressCurrentPage.value += 1;
        const searchDataProgress = { id: apiData.value.id, page: progressCurrentPage.value, limit: progressPageSize.value };

        getDonationProgressList(searchDataProgress).then((res) => {
            progressPending.value = false;
            if (res === false) return;

            progressList.value.push(...res.data.data);

        }).catch((rej) => {
            progressPending.value = false;
            message.error('错误：' + rej);
        });
    }
}

// 项目介绍
const introduceIsShowMore = ref(false);
const introduceShowMore = () => {
    introduceIsShowMore.value = !introduceIsShowMore.value;
}

// 项目预算及执行计划
const budgetIsShowMore = ref(false);
const budgetShowMore = () => {
    budgetIsShowMore.value = !budgetIsShowMore.value;
}

onMounted(() => {
    getData()
})
</script>

<style scoped>
.page_content {
    background-color: #ffffff;
}

.data-content {
    padding: 20rem 0;
}

.img {
    width: 100%;
    border-radius: 8rem;
}

.title {
    margin-top: 26rem;
    height: 33rem;
    font-weight: 600;
    font-size: 24rem;
    color: #333333;
}

.tags {
    margin-top: 5rem;
    display: flex;
    justify-content: flex-start;
}

.tags>span {
    text-align: center;
    height: 21rem;
    line-height: 21rem;
    background: #FFF1F0;
    border-radius: 3rem;
    padding: 0 5rem;
    font-weight: 400;
    font-size: 12rem;
    color: #D4352D;
    margin-right: 10rem;
}

.tags>span:last-child {
    margin-right: 0;
}

.desc {
    margin-top: 12rem;
    font-weight: 400;
    font-size: 12rem;
    color: #444444;
    line-height: 17rem;
}

.detail .icon {
    margin-top: 40rem;
    display: flex;
    justify-content: space-between;
    padding: 0 20rem;
}

.detail .icon>.list {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    width: 25%;
}

.detail .icon>.list>img {
    width: 30rem;
    height: 30rem;
}

.detail .icon>.list>.title {
    margin-top: 12rem;
    height: 20rem;
    line-height: 20rem;
    font-weight: 600;
    font-size: 14rem;
    color: #333333;
}

.detail .icon>.list>.desc {
    margin-top: 3rem;
    height: 17rem;
    line-height: 17rem;
    font-weight: 400;
    font-size: 12rem;
    color: #999999;
}

.line {
    margin-top: 40rem;
    height: 2rem;
    background: #EDF1F2;
}

.progress {
    margin-top: 40rem;
}

.progress>.list {
    margin-top: 27rem;
    padding-left: 14rem;
}

:deep(.progress>.list .ant-timeline .ant-timeline-item) {
    padding-bottom: 20rem;
}

:deep(.progress>.list .ant-timeline .ant-timeline-item-pending) {
    margin-top: 20rem;
}

:deep(.progress>.list .ant-timeline .ant-timeline-item-last) {
    padding-bottom: 0;
}

:deep(.progress>.list .ant-timeline .ant-timeline-item-tail) {
    inset-block-start: 10rem;
    inset-inline-start: 4rem;
    height: calc(100% - 10rem);
    border-inline-start: 2rem solid red;
}

:deep(.progress>.list .ant-timeline .ant-timeline-item-head) {
    width: 10rem;
    height: 10rem;
    border-width: 3rem;
}

:deep(.progress>.list .ant-timeline .ant-timeline-item-content) {
    inset-block-start: -2rem;
    margin-inline-start: 26rem;
}

:deep(.progress>.list .ant-timeline-item-pending .ant-timeline-item-head) {
    color: red;
    font-size: 12rem;
    inset-block-start: 5rem;
    inset-inline-start: 5rem;
    padding-block: 4rem;
}

:deep(.progress>.list .ant-timeline-item-pending .ant-timeline-item-content) {
    color: red;
    font-size: 14rem;
}

.progress>.list .author {
    line-height: 17rem;
    font-weight: 400;
    font-size: 12rem;
    color: #999999;
}

.progress>.list .title {
    margin-top: 8rem;
    font-weight: bold;
    font-size: 14rem;
    color: #000000;
    line-height: 20rem;
}

.progress>.list .content {
    margin-top: 5rem;
    line-height: 18rem;
    font-weight: 400;
    font-size: 12rem;
    color: #666666;
}

.progress>.list .more {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    cursor: pointer;
}

.progress>.list .more>.word {
    font-weight: bold;
    font-size: 14rem;
    color: red;
}

.progress>.list .more>.to_bottom_icon {
    margin-left: 5rem;
    width: 14rem;
    height: 14rem;
}

.situation {
    margin-top: 40rem;
    position: relative
}

.situation>.more_desc {
    color: #D4352D;
    font-weight: 500;
    font-size: 14rem;
    position: absolute;
    right: 0;
    top: 2rem;
}

.situation>.title {
    margin-top: 18rem;
    height: 20rem;
    line-height: 20rem;
    font-weight: 400;
    font-size: 14rem;
    color: #666666;
    padding-left: 14rem;
}

.situation>.list {
    margin-top: 30rem;
    display: flex;
    justify-content: space-around;
    align-items: center;
}

.situation>.list>.box>.num {
    height: 47rem;
    line-height: 47rem;
    text-align: center;
    font-weight: bold;
    font-size: 40rem;
    color: #D4352D;
}

.situation>.list>.box>.text {
    margin-top: 2rem;
    height: 20rem;
    line-height: 20rem;
    text-align: center;
    font-weight: 400;
    font-size: 14rem;
    color: #333333;
}

.introduce {
    margin-top: 40rem;
    position: relative
}

.introduce>.content {
    margin-top: 18rem;
    padding-left: 14rem;
    font-weight: 400;
    font-size: 14rem;
    color: #666666;
    line-height: 20rem;
}

.introduce>.more_btn {
    cursor: pointer;
    padding-left: 14rem;
    margin-top: 6rem;
    height: 20rem;
    line-height: 20rem;
    font-weight: 400;
    font-size: 14rem;
    color: #D4352D;
}

.organization {
    margin-top: 40rem;
    position: relative
}

.organization>.title {
    margin-top: 16rem;
    height: 20rem;
    line-height: 20rem;
    font-weight: 400;
    font-size: 14rem;
    color: #666666;
    padding-left: 14rem;
}

.organization>.agency {
    margin-top: 10rem;
    line-height: 20rem;
    font-weight: 500;
    font-size: 14rem;
    color: #333333;
    padding-left: 14rem;
}

.organization>.person_list {
    padding-left: 14rem;
}

.organization>.person_list>.box {
    margin-top: 10rem;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    flex-direction: row;
}

.organization>.person_list>.box>.head_img {
    width: 50rem;
    height: 50rem;
    border-radius: 50%;
}

.organization>.person_list>.box>.info {
    margin-left: 20rem;
    padding-top: 15rem;
}

.organization>.person_list>.box>.info>.name {
    height: 20rem;
    line-height: 20rem;
    font-weight: 500;
    font-size: 14rem;
    color: #333333;
}

.organization>.person_list>.box>.info>.desc {
    margin-top: 10rem;
    font-weight: 400;
    font-size: 12rem;
    color: #666666;
    line-height: 18rem;
}

/*手机端样式*/
@media screen and (max-width: 800px) {
    .title {
        margin-top: 10rem;
        height: 22rem;
        line-height: 22rem;
        font-size: 16rem;
    }

    .tags>span {
        height: 17rem;
        line-height: 17rem;
        font-size: 10rem;
        margin-right: 5rem;
    }

    .desc {
        margin-top: 8rem;
        font-size: 12rem;
        line-height: 17rem;
    }

    .detail .icon {
        margin-top: 10rem;
        padding: 0;
    }

    .detail .icon>.list>img {
        width: 22rem;
        height: 22rem;
    }

    .detail .icon>.list>.title {
        margin-top: 7rem;
        font-size: 10rem;
        height: 14rem;
        line-height: 14rem;
    }

    .detail .icon>.list>.desc {
        margin-top: 4rem;
        font-size: 10rem;
        height: 14rem;
        line-height: 14rem;
    }

    .line {
        margin-top: 15rem;
        height: 6rem;
        background: #EDF1F2;
        width: 100%;
    }

    .progress {
        margin-top: 15rem;
    }

    .progress>.list {
        margin-top: 11rem;
        padding-left: 0;
    }

    .progress>.list .title {
        margin-top: 4rem;
    }

    .progress>.list .content {
        margin-top: 8rem
    }

    .progress>.list .more>.word {
        font-size: 12rem;
    }

    .progress>.list .more>.to_bottom_icon {
        width: 12rem;
        height: 12rem;
    }

    :deep(.progress>.list .ant-timeline .ant-timeline-item) {
        padding-bottom: 12rem;
    }

    :deep(.progress>.list .ant-timeline .ant-timeline-item-pending) {
        margin-top: 12rem;
    }

    :deep(.progress>.list .ant-timeline .ant-timeline-item-last) {
        padding-bottom: 0;
    }

    .situation {
        margin-top: 15rem;
    }

    .situation>.title {
        padding-left: 0;
        margin-top: 10rem;
        height: 17rem;
        line-height: 17rem;
        font-size: 12rem;
    }

    .situation>.list {
        margin-top: 25rem;
        justify-content: space-between;
    }

    .situation>.list>.box>.num {
        height: 24rem;
        line-height: 24rem;
        font-size: 20rem;
    }

    .situation>.list>.box>.text {
        margin-top: 8rem;
        height: 17rem;
        line-height: 17rem;
        font-size: 12rem;
    }

    .introduce {
        margin-top: 15rem;
    }

    .introduce>.content {
        padding-left: 0;
        font-size: 12rem;
        margin-top: 8rem;
    }

    .introduce>.more_btn {
        padding-left: 0;
        margin-top: 10rem;
        height: 17rem;
        line-height: 17rem;
        font-size: 12rem;
    }

    .organization {
        margin-top: 15rem;
    }

    .organization>.title {
        padding-left: 0;
        margin-top: 10rem;
        height: 17rem;
        line-height: 17rem;
        font-size: 12rem;
    }

    .organization>.agency {
        padding-left: 0;
        margin-top: 6rem;
        line-height: 17rem;
        font-size: 12rem;
    }

    .organization>.person_list {
        padding-left: 0;
        margin-top: 10rem;
    }

    .organization>.person_list>.box>.head_img {
        width: 30rem;
        height: 30rem;
    }

    .organization>.person_list>.box>.info {
        margin-left: 11rem;
        padding-top: 5rem;
    }

    .organization>.person_list>.box>.info>.name {
        height: 17rem;
        line-height: 17rem;
        font-size: 12rem;
    }

    .organization>.person_list>.box>.info>.desc {
        margin-top: 8rem;
        line-height: 17rem;
        font-size: 12rem;
    }

}
</style>
